//
//  QLSearchView.swift
//  WeiBo
//
//  Created by 黄跃奇 on 16/9/20.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class QLSearchView: UIView {
    
    
    @IBOutlet weak var searchTextFieldRightConstraint: NSLayoutConstraint!

    @IBOutlet weak var searchButton: UIButton!
    
    @IBOutlet weak var searchTextField: UITextField!

    @IBAction func editBeginAction(_ sender: AnyObject) {
        
        searchTextFieldRightConstraint.constant = searchButton.width
        //设置动画效果
        UIView.animate(withDuration: 0.3) { 
            self.layoutIfNeeded()
        }
        
    }
    
    @IBAction func searchButtonAction(_ sender: AnyObject) {
        
        //辞去第一响应者
        searchTextField.resignFirstResponder()
        searchTextFieldRightConstraint.constant = 0
        //设置动画效果
        UIView.animate(withDuration: 0.3) {
            self.layoutIfNeeded()
        }
    }
    
    
    //使用类方法创建xib
    class func searchView() -> QLSearchView {
        
        return UINib(nibName: "QLSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last! as! QLSearchView
        
    }
    
    //设置搜索框的属性
//    override func awakeFromNib() {
//        searchTextField.layer.borderColor = UIColor.blue.cgColor
//        searchTextField.layer.borderWidth = 2
//        searchTextField.layer.cornerRadius = 5
//        searchTextField.layer.masksToBounds = true
//    }
    
    
}
